﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using System.Data;
using MySql.Data.MySqlClient;
using Microsoft.Extensions.Configuration;
using Helpers;
using EasyCaching.Core;
using EasyCaching.CSRedis;
using Serilog;

namespace Helpers.UnitTest
{
    public class TestBase
    {
        protected readonly IEasyCachingProviderFactory _easyCachingProviderFactory;
        protected IConfiguration _configuration = null;
        public TestBase()
        {
            _configuration = new ConfigurationBuilder()
                .AddJsonFile("logs.json")
                .AddUserSecrets("bb14c8c9-52ec-423f-b7fa-aa5ccfa290e6")
                .Build();
            DiHelper.Services
                .AddCsRedisHelperz(_configuration)
                .AddMemoryCache()
                .AddEasyCaching(options =>
                {
                    options.UseInMemory("default");
                    options.UseCSRedis(config =>
                    {
                        config.DBConfig.ConnectionStrings = new List<string> { "127.0.0.1:3680,password=gangan168,defaultDatabase=13,prefix=test:" };
                    }, "redis");
                });
            //RedisHelper.Initialization(DiHelper.GetRequiredService<EasyCachingCSRedisClient>());
            _easyCachingProviderFactory = DiHelper.GetRequiredService<IEasyCachingProviderFactory>();

            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                .WriteTo.Console()
                .WriteTo.Debug()
                .CreateLogger();
            Log.Information("组件初始化完成");
        }
    }
}
